import java.io.*;

import java.awt.geom.Point2D;
import java.sql.Time;
import java.text.*;
import java.math.*;
import java.util.*;

public class C implements Runnable {

	final String filename = "/home/xerxes/Documents/Programming/CROC-MBTU 2012/src/in1";

	public static void main(String[] args) {
		// new Thread(new Main()).start();
		new Thread(null, new C(), "1", 1 << 25).start();
	}

	public void run() {
		try {
			 in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			//in = new BufferedReader(new FileReader(filename));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			int kase = 1;// iread();
			for (int i = 1; i <= kase; ++i) {
				solve(i);
			}
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public void solve(int kaseno) throws Exception {
		String[] tmp = in.readLine().split(" ");
		n = Integer.parseInt(tmp[0]);
		m = Integer.parseInt(tmp[1]);

		q = new ArrayDeque<Long>();
		while (true) {
			String S = in.readLine();
			if (S == null)
				break;
			String[] s = S.split("[ ]");
			String[] p1 = s[0].split("[-]");
			String[] p2 = s[1].split("[:]");

			int yr = Integer.parseInt(p1[0]);
			int mn = Integer.parseInt(p1[1]);
			int da = Integer.parseInt(p1[2]);
			int hr = Integer.parseInt(p2[0]);
			int mnt = Integer.parseInt(p2[1]);
			int sec = Integer.parseInt(p2[2]);

			Calendar cal = Calendar.getInstance();
			cal.set(yr, mn - 1, da, hr, mnt, sec);
			Long curTime = cal.getTimeInMillis();
			if (q.isEmpty()) {
				q.add(curTime);
			} else {
				long advance = q.peek() + (n * 1000);
				if (curTime + 1 > advance) {
					q.poll();
				}
				q.add(curTime);
				if (q.size() >= m) {
					out.write(p1[0] + "-" + p1[1] + "-" + p1[2] + " " + p2[0]
							+ ":" + p2[1] + ":" + p2[2] + "\n");
					return;
				}
			}
		}
		out.write("-1\n");
	}

	public void debug(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;
	BufferedWriter out;
	private int n;
	private int m;
	private Queue<Long> q;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ') {
			c = in.read();
		}
		if (c < 0) {
			return "";
		}
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}
}